package com.demo.juc.future.completableFuture;

import java.util.concurrent.CompletableFuture;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2023/5/24 16:49
 * @Version: 1.0
 */
public class Demo3 {

    public static void main(String[] args) {
        CompletableFuture<Integer> future1
                = CompletableFuture.supplyAsync(()->{
            System.out.println("compute 1");
            return 1;
        });
        CompletableFuture future2
                = future1.whenComplete((r, e)->{
            if(e != null){
                System.out.println("compute failed!");
            } else {
                System.out.println("received result is " + r);
            }
        });
        System.out.println("result: " + future2.join());

    }
}
